package com.lancoo.answer.widget.combinationView;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lancoo.answer.R;
import com.lancoo.answer.util.ExamFontSizeAdjustUtils;
import com.lancoo.answer.util.RichTextUtils;

/**
 * Created by pengmi on 2021/12/14 10:58
 * Description:听力原文看组合View
 */
public class ListenArticleView extends LinearLayout {

    private static final String TAG = "ListenArticleView";
    private TextView tv_analysis;

    public ListenArticleView(Context context) {
        super(context);
        init(context);
    }

    public ListenArticleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ListenArticleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }


    private void init(Context context){
        LayoutInflater.from(context).inflate(R.layout.ev_layout_listen_article,this);
        TextView tv_title=findViewById(R.id.tv_title);
        tv_analysis = findViewById(R.id.tv_analysis);
        String str="【";
        float v = tv_title.getPaint().measureText(str);
        Log.e(TAG,"width:"+v);
        tv_title.setTranslationX(-v/3);
        adjustFontSize();
    }

    public void setArticle(String analysis,boolean isNeedTr){
        if(TextUtils.isEmpty(analysis)){
            tv_analysis.setText(R.string.ev_item_null);
        }else{
            Log.e("听力题","isNeedTr:"+isNeedTr);
            tv_analysis.setText(RichTextUtils.getAudioArticle(analysis,isNeedTr));
        }
    }

    public void adjustFontSize(){
        TextView tv_title = findViewById(R.id.tv_title);
        TextView tv_analysis = findViewById(R.id.tv_analysis);
        ExamFontSizeAdjustUtils.adjustTextViewFontSize(tv_analysis,13);
        ExamFontSizeAdjustUtils.adjustTextViewFontSize(tv_title,14);
        tv_title.invalidate();requestLayout();
        Log.e("qwewq","ListenArticleQuseBodyFragment adjustFontSize");
    }

}
